﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace ePharmacyLauch
{
    public partial class ucButton : UserControl
    {
        public ucButton()
        {
            InitializeComponent();
            
            this.lbText.Click += (sender, e) =>
            {
                this.OnClick(e);
            };

            this.btStatus.Click += (sender, e) =>
            {
                this.OnClick(e);
            };
            
        }

        public ContentAlignment CaptionAlignment
        {
            get { return this.lbText.TextAlign; }
            set { this.lbText.TextAlign = value; }
        }

        public string Caption  
        {
            get { return this.lbText.Text; }
            set { this.lbText.Text = value; }
        }

        public Button CtrlButton
        {
            get { return this.btStatus; }
        }

        public Label CtrlLabel
        {
            get { return this.lbText; }
        }

        private ButtonMode mode = ButtonMode.Normal;
        public ButtonMode Mode
        {
            get { return this.mode; }
            set { this.mode = value; RefreshMode(); }
        }

        protected virtual void RefreshMode()
        {
            switch (this.mode)
            {
                case ButtonMode.Normal:
                    this.btStatus.BackColor = this.lbText.ForeColor = Color.RoyalBlue; break;
                case ButtonMode.Insert:
                    this.btStatus.BackColor = this.lbText.ForeColor = Color.LimeGreen; break;
                case ButtonMode.Update:
                    this.btStatus.BackColor = this.lbText.ForeColor = Color.OrangeRed; break;
                case ButtonMode.Delete:
                    this.btStatus.BackColor = this.lbText.ForeColor = Color.Goldenrod; break;
                case ButtonMode.Custom:
                    break;
            }
        }

        private void lbText_MouseLeave(object sender, EventArgs e)
        {
            RefreshMode();
        }

        private void btStatus_MouseLeave(object sender, EventArgs e)
        {
            lbText_MouseLeave(sender, e);
        }

        private void lbText_MouseEnter(object sender, EventArgs e)
        {
            this.btStatus.BackColor = Color.DarkViolet;
            this.lbText.ForeColor = Color.DarkViolet;
        }

        private void btStatus_MouseEnter(object sender, EventArgs e)
        {
            lbText_MouseEnter(sender, e);
        }
        
    }

    public enum ButtonMode
    { 
        Normal = 0,
        Update = 1,
        Insert = 2,
        Delete = 4,
        Custom = 8
    }
}
